package com.example.demo.threadTest;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


/**
 * @author leiliang
 * @version 1.0
 * @Description
 * @date 2022/8/12 15:20
 */
public class ThreadCallMain {
    public static void main(String[] args) throws Exception {
        // 实例化继承Callable接口的MyThread类
        MyThreadCallable mt1 = new MyThreadCallable("线程一");
        MyThreadCallable mt2 = new MyThreadCallable("线程二");

        // FutureTask类接收继承Callable接口的MyThread的实例
        FutureTask<Integer> ft1 = new FutureTask<Integer>(mt1);
        FutureTask<Integer> ft2 = new FutureTask<Integer>(mt2);
        List<FutureTask<Integer>> futureTaskList = new ArrayList<>();
        futureTaskList.add(ft1);
        futureTaskList.add(ft2);
        // 启动多线程
        new Thread(ft1).start();
        new Thread(ft2).start();
        for (FutureTask<Integer> i : futureTaskList) {
            try {
                System.out.printf("查询结果" + i.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
       /*  System.out.println(ft1.get());
        System.out.println(ft2.get());*/
    }

}
